<?php 
	$front = Zend_Controller_Front::getInstance();
	
	//get module name
	$module =  $front->getRequest()->getModuleName();
	
	//get controller name
	$controller = $front->getRequest()->getControllerName();
	
	//get action	
	$action = $front->getRequest()->getActionName(); 
?>
<form id="frmAdminForm" method="get"> 
	<div class="searchBox">
	
			<!-- title -->
			<div class="searchBoxLeft">
				<label class="title">Tìm kiếm</label>
			</div>
			
			<!-- search field-->
			<div class="searchBoxRight">
				<div class="blockField clearfix">
					<label for="keyword">Từ khóa</label>  				
					<input type="text"	name="keyword" value="<?php echo $this->keyword;?>" id="keyword">								 
				</div>	
					
				<div class="blockField clearfix">	
					<label for="category" >Phân loại:</label>				
					<select name="category" id="category">
						<option value="0">Tất cả</option>
						<?php $categoryMD = new Application_Model_DbTable_Category();
							$arrCat = $categoryMD->fetchAll();
							foreach($arrCat as $item){
								if($item['category_id'] == $this->category){
									$selected="selected=selected";
								}else{
									$selected="";
								}
								echo "<option value='".$item['category_id']."' $selected>".$item['category_name_vi']."</option>";
							}
						?>
					</select>	
				</div>
				<div class="blockField clearfix">	
						<label for="manufacture" >Hãng sản xuất:</label>				
						<select name="manufacture" id="manufacture">
							<option value="0">Tất cả</option>
							<?php $manufactureMD = new Application_Model_DbTable_Manufacture();
								$arrManu = $manufactureMD->fetchAll();
								foreach($arrManu as $item){
									if($item['manufacture_id'] == $this->manufacture){
										$selected="selected=selected";
									}else{
										$selected="";
									}
									echo "<option value='".$item['manufacture_id']."' $selected>".$item['manufacture_name']."</option>";
								}
							?>
						</select>		
				</div>		
					
				<div class="blockField clearfix">	
					<label for="startPrice">Giá từ</label> 
					<select name="startPrice"	id="startPrice" >
						<option value="0">Thấp nhất</option>
							<?php
							$selected = "";
							for($i = 1; $i <= 15; $i += 2) {
								$price = $i * 1000000;
								if ($price == $this->startPrice)
									$selected = "selected=selected";
								else {
									$selected = "";
								}
								echo "<option value='" . $price . "'  $selected>" . number_format ( $price, 0, '.', '.' ) . "</option>";
							}
							?>
					</select>
				</div>		
				
				<div class="blockField clearfix">
					<label for="endPrice">Giá đến</label> 
					<select name="endPrice"	id="endPrice" >
						<option value="max">cao nhất</option>
						<?php 			
							$selected = "";
							for($i=7;$i<=25;$i+=2){
								$price = $i*1000000;
								if($price==$this->endPrice)
									$selected="selected=selected";
								else{
									$selected = "";
								}
								
								echo "<option value='".$price."'  $selected>".number_format($price,0,'.','.')."</option>";
							}
						?>
					</select> 
				</div>
				
				<div class="blockField clearfix">
					<label for="searchStatus">Trạng thái</label> 
					<select name="searchStatus"	id="searchStatus">
						<option value="">Trạng thái</option>
						<option value="1" <?php echo ($this->status=="1") ? "selected=selected" : ""; ?> >Kích hoạt</option>
						<option value="0" <?php echo ($this->status=="0") ? "selected=selected" : ""; ?> >Ẩn</option>
					</select> 
				</div>
				
				<div class="blockField clearfix">
					<label for="fromDate">Từ ngày</label> 
					<input type="text"
						name="fromDate" value="<?php echo $this->fromDate?>"
						class="datepicker" id="fromDate"> 
				</div>

				<div class="blockField clearfix">
					<label for="toDate">Đến ngày</label>
					<input type="text" name="toDate" value="<?php echo $this->toDate?>"
						class="datepicker" id="toDate"> 			
				</div>
				<!-- <div class="clearb"></div> -->
				<div class="blockField clearfix submit">
					<button name="search" class='button'> Tìm kiếm </button>
					<input type='reset' value="Xóa"
						name="reset" class="reset button" />
				</div>
				<div class="clearb"></div>
			</div>
			
			<!-- filter -->
		
		<div class="clearb"></div>
	</div>

	<!-- list table -->
	<div class="listElement">
		
			<table>
				<thead>
					<tr>
						<th>STT</th>
						<th>
							<input type="checkbox" id="checkall" value='checkall' /><label
								for="checkall"></label>
						</th>
						<th>
							<?php echo $this->partial('partial/sort.phtml','admin',array(
								'columnname'=>'product_name',
								'columntitle'=>'Tên sản phẩm')
							)?>
						</th>
						<th>
							<?php echo $this->partial('partial/sort.phtml','admin',array(
								'columnname'=>'product_category_id',
								'columntitle'=>'Phân loại')
							)?>
						</th>
						<th>
							<?php echo $this->partial('partial/sort.phtml','admin',array(
								'columnname'=>'product_manufacture_id',
								'columntitle'=>'Hãng sản xuất')
							)?>
						</th>
						<th>
							<?php echo $this->partial('partial/sort.phtml','admin',array(
								'columnname'=>'product_price',
								'columntitle'=>'Giá tiền ( VND )')
							)?>
						</th>
						<th>Hình ảnh</th>
						<th>
							<?php echo $this->partial('partial/sort.phtml','admin',array(
								'columnname'=>'product_creation_time',
								'columntitle'=>'Ngày đăng')
							)?>
						</th>
						<th>
							<?php echo $this->partial('partial/sort.phtml','admin',array(
								'columnname'=>'product_status',
								'columntitle'=>'Trạng thái')
							)?>
						</th>
						<th>
							<?php echo $this->partial('partial/sort.phtml','admin',array(
								'columnname'=>'product_hot',
								'columntitle'=>'Hot')
							)?>
						</th>
						<th>Thao tác</th>
					</tr>
				</thead>
				<tbody>
					<?php 
						//số thứ tự bằng trang hiện tạ - 1, nhân với số phần tử hiển thị trong trang.
						$stt = ($this->paginator->getCurrentPageNumber()-1)*$this->paginator->getItemCountPerPage();
						$stt+=1;
					?>
					<?php 
						foreach($this->paginator as $item):
							$status = "Có";
							if($item['product_status']==0){
								$status = "Không";
							}
					?>
					
					<tr>
						<td><?php echo $stt++?></td>
						<td><input type="checkbox" value="<?php echo $item['product_id']?>"
							name="id[]" /></td>
						<td>
							<?php echo $item["product_name"]?>
							<br />
							<?php echo "alias: ". $item['product_alias']?>
						</td>
						<td><?php echo $item->findParentRow('Application_Model_DbTable_Category')->category_name_vi?></td>
						<td><?php echo $item->findParentRow('Application_Model_DbTable_Manufacture')->manufacture_name?></td>
						<td><?php echo number_format($item["product_price"],'0','.','.')?></td>
						<td><img
							src='<?php echo PUBLIC_RESOURCE.'/uploads/images/products/thumbs/'.$item["product_image"]?>'
							alt='<?php echo $item["product_image"]?>' class="thumbs" /></td>
						<td>
							<?php 
								$date = date_create($item['product_creation_time']);
								echo date_format($date, 'd/m/Y');
							?>
						</td>
						<td>
							
							<?php 
							
							$status = ((int)$item['product_status']==1)? "publish" : "unpublish";
							echo $this->partial('partial/icon.phtml','admin',array(
									'title'=>'kích hoạt hoặc vô hiệu',
									'href'=>$this->baseUrl('/admin/product/changestatus/id/').$item['product_id'],
									'a_class'=>'changestatus',
									'class'=>$status
									
							))?>
		
						</td>
						<td>
							
							<?php 
							
							$status = ((int)$item['product_hot']==1)? "publish" : "unpublish";
							echo $this->partial('partial/icon.phtml','admin',array(
									'title'=>'kích hoạt hoặc vô hiệu',
									'href'=>$this->baseUrl('/admin/product/changehot/id/').$item['product_id'],
									'a_class'=>'changestatus',
									'class'=>$status
									
							))?>
		
						</td>
						<td>
							<a
								href="<?php echo $this->baseUrl()."/admin/".$controller."/upload/id/{$item["product_id"]}"?>"
								title="Thêm hình ảnh" class="upload-img option"> 
								<span class="small-upload-img-icon">&nbsp;</span>
							</a> 
							
							<a
								href="<?php echo $this->baseUrl()."/admin/".$controller."/update/id/{$item["product_id"]}"?>"
								title="cập nhật" class="edit option"> 
								<span class="small-edit-icon">&nbsp;</span>
							</a> 
							<a
								href="<?php echo $this->baseUrl()."/admin/".$controller."/delete/id/{$item["product_id"]}"?>"
								title="xóa" class="delete option"> 
								<span class="small-delete-icon">&nbsp;</span>
							</a>
						</td>
					</tr>
					<?php endforeach;?>
				</tbody>
			</table>
		<input type="hidden" name='order' value="" id="order" />
		<div class="controller">										
			<?php echo $this->paginationControl($this->paginator,'Sliding','partial/pagination.phtml'); ?>	
		</div>
	</div><!--  end list element -->
</form>
<div class="clearb">&nbsp;</div>